package org.yxt.springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.yxt.springcloud.entities.CommonResult;
import org.yxt.springcloud.entities.Payment;

@RestController
@RequestMapping(value = "consumer")
public class OrderController {

    // 使用微服务注册名称不再是具体地址信息
    //public final String PAYMENT_URL = "http://localhost:8001";
    public final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE/";

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 新增
     *
     * @param payment
     * @return
     */
    @GetMapping("/payment/create")
    public CommonResult<Payment> creat(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL.concat("/payment/create"), payment, CommonResult.class);
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable Long id) {
        return restTemplate.getForObject(PAYMENT_URL.concat("/payment/get/").concat(String.valueOf(id)), CommonResult.class);
    }

    /**
     * 链路追踪
     *
     * @return
     */
    @GetMapping("/payment/zipkin")
    public CommonResult zipkin() {
        return restTemplate.getForObject(PAYMENT_URL.concat("/payment/zipkin"), CommonResult.class);
    }
}
